<?php

namespace app\admin\model\resource;

use think\Model;


class Merchant extends Model
{

    

    

    // 表名
    protected $name = 'merchant';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'business_entity_text',
        'service_method_text',
        'billing_cycle_text',
        'settlement_method_text',
        'sex_data_text'
    ];
    

    
    public function getBusinessEntityList()
    {
        return [''=>'请选择','个体' => __('个体'), '机构' => __('机构')];
    }

    public function getServiceMethodList()
    {
        return [''=>'请选择','采购' => __('采购'), '租赁' => __('租赁')];
    }

    public function getBillingCycleList()
    {
        return [''=>'请选择','月度结算' => __('月度结算'), '按次结算' => __('按次结算'), '季度结算' => __('季度结算'), '年度结算' => __('年度结算')];
    }

    public function getSettlementMethodList()
    {
        return [''=>'请选择','现金收支' => __('现金收支'), '支票收支' => __('支票收支'), '现金转账' => __('现金转账'), '银行转账' => __('银行转账'), '公户转公户' => __('公户转公户'), '公户转个人' => __('公户转个人')];
    }

    public function getSexDataList()
    {
        return ['男' => __('男'), '女' => __('女')];
    }


    public function getBusinessEntityTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['business_entity']) ? $data['business_entity'] : '');
        $list = $this->getBusinessEntityList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getServiceMethodTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['service_method']) ? $data['service_method'] : '');
        $list = $this->getServiceMethodList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getBillingCycleTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['billing_cycle']) ? $data['billing_cycle'] : '');
        $list = $this->getBillingCycleList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getSettlementMethodTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['settlement_method']) ? $data['settlement_method'] : '');
        $list = $this->getSettlementMethodList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getSexDataTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['sex_data']) ? $data['sex_data'] : '');
        $list = $this->getSexDataList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function admin()
    {
        return $this->belongsTo('app\admin\model\Admin', 'principal_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
